﻿using UnityEngine;
using System.Collections;

public class DeskTigger : MonoBehaviour {

	private GameObject[] m_Desk;
	void Start () {
		m_Desk = GameObject.FindGameObjectsWithTag ("Desk");
		/*
		for (int i = 0; i < m_Desk.Length; i++) {
			Debug.Log (m_Desk[i].name);
		}
		*/
	}

	void Update () {
		if(Input.GetKeyDown(KeyCode.Z)){
			//up.
			DeskUp();
		}

		if(Input.GetKeyUp(KeyCode.Z)){
			DeskDown ();
			//down.
		}
	}

	 void DeskUp()
	{
		for(int i = 0; i < m_Desk.Length; i++){
			m_Desk[i].GetComponent<Transform>().Translate(Vector3.up*2, Space.Self);
		}
	}

	 void DeskDown()
	{
		for(int i = 0; i < m_Desk.Length; i++){
			m_Desk[i].GetComponent<Transform>().Translate(Vector3.up*-2, Space.Self);
		}
	}

	void OnTriggerEnter(Collider collider){
		if (collider.gameObject.name == "Student") {
			DeskUp ();
		}
	}

	void OnTriggerExit(Collider collider){
		if (collider.gameObject.name == "Student") {
			DeskDown ();
		}
	}
}
